/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.cef.generator.coreGenerator.base.accessorgen.property;

import com.inspur.edp.cef.api.attr.ChildAttribute;
import com.inspur.edp.cef.gencommon.CefPropertyInfo;
import com.inspur.edp.cef.generator.common.MediatePropertyInfo;
import com.inspur.edp.cef.generator.coreGenerator.base.entitygen.EntityGeneratorContext;
import com.inspur.edp.cef.generator.coreGenerator.base.entitygen.property.ChildPropGenerator;
import com.inspur.edp.cef.generator.overall.Utils;
import org.eclipse.jdt.core.dom.Block;
import org.eclipse.jdt.core.dom.MethodInvocation;
import org.eclipse.jdt.core.dom.ReturnStatement;

public class AccessorChildCollectionProperty extends ChildPropGenerator
{
	public AccessorChildCollectionProperty(EntityGeneratorContext parentContext,String childCode, MediatePropertyInfo propertyInfo,
			String privatePropName)
	{
		super(parentContext, childCode, propertyInfo, privatePropName);
	}

	//protected override Type getPropertyType()
	//{
	//    return typeof(IEntityDataCollection);
	//}


	@Override
	protected Block buildGetMethodBody() {
		Block block=ast.newBlock();
		if(Character.isLowerCase(getPropertyInfo().getPropertyName().charAt(0))){//小写
			ReturnStatement returnStatement = ast.newReturnStatement();
			MethodInvocation methodInvocation = ast.newMethodInvocation();
			methodInvocation.setName(ast.newSimpleName(Utils.getGetterMethodName(toUpperCaseFirstOne(getPropertyInfo().getPropertyName()))));
			returnStatement.setExpression(methodInvocation);
			block.statements().add(returnStatement);
		}
		else {
			ReturnStatement returnStatement=ast.newReturnStatement();
			returnStatement.setExpression(ast.newSimpleName(PrivatePropName));
			block.statements().add(returnStatement);
		}
		return block;
	}

	private String toUpperCaseFirstOne(String s){
		if(Character.isUpperCase(s.charAt(0)))
			return s;
		else
			return (new StringBuilder()).append(Character.toUpperCase(s.charAt(0))).append(s.substring(1)).toString();
	}
}
